#include "ad_professionalsmgrlisr.h"
#include "ui_ad_professionalsmgrlisr.h"

AD_ProfessionalsMgrLisr::AD_ProfessionalsMgrLisr(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::AD_ProfessionalsMgrLisr)
{
    ui->setupUi(this);

    model = new QSqlTableModel();
    model->setTable("professionals");
    model->select();
    model->setEditStrategy(QSqlTableModel::OnFieldChange);
    model->setHeaderData(0, Qt::Horizontal, tr("专业ID"));
    model->setHeaderData(1, Qt::Horizontal, tr("专业名称"));

    ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->tableView->verticalHeader()->setHidden(true);

    ui->tableView->setModel(model);
}

AD_ProfessionalsMgrLisr::~AD_ProfessionalsMgrLisr()
{
    delete ui;
}

void AD_ProfessionalsMgrLisr::on_pushButton_clicked()
{
    //获取表的行数
    int row = model->rowCount();

    //添加一行
    model->insertRow(row);

    model->setData(model->index(row, 0), model->data(model->index(row-1,0)).toInt()+1);
    model->setData(model->index(row, 1), tr("专业名称"));

    //提交
}

void AD_ProfessionalsMgrLisr::on_pushButton_2_clicked()
{
    //获取选中的行
    int curRow = ui->tableView->currentIndex().row();

    //删除该行
    model->removeRow(curRow);

    model->select();
}

